using System;
using System.Xml;

namespace XMLTest
{
	public class SimpleXML
	{
		
		public void ReadXMLFile()
		{
			// Modify this path to find books.xml
			string fileName = @"/mnt/hdd1/work/tests/c_sharp/XMLTest/XMLTest/settings.xml";
			// Create the new TextReader Object
			XmlTextReader tr = new XmlTextReader(fileName);
			
			// Read in a node at a time
			while (tr.Read ()) {
				if(tr.NodeType == XmlNodeType.Element) {
					switch (tr.Name) {
						case "hostName":
							Console.WriteLine ("hostName: " + tr.ReadElementString ());
						break;
						case "dbName":
							Console.WriteLine ("dbName: " + tr.ReadElementString ());
						break;
						case "userName":
							Console.WriteLine ("userName: " + tr.ReadElementString ());
						break;
						case "password":
							Console.WriteLine ("password: " + tr.ReadElementString ());
						break;
					}
				}
			}
		}
		
		public void WriteXMLFile ()
		{
			// change to match your path structure
			string fileName = @"/mnt/hdd1/work/tests/c_sharp/XMLTest/XMLTest/settings.xml";
			// create the XmlTextWriter
			XmlTextWriter tw = new XmlTextWriter(fileName, null);
			
			// set the formatting to indented
			tw.Formatting = Formatting.Indented;
			tw.WriteStartDocument();
			
			// Start creating elements and attributes
			tw.WriteStartElement("settings");

			tw.WriteStartElement("connectionSettings");
			tw.WriteElementString("hostName", "10.10.13.1");
			tw.WriteElementString("dbName", "XE");
			tw.WriteElementString("userName", "radu");
			tw.WriteElementString("password", "panamea");
			tw.WriteEndElement();
			
			
			tw.WriteEndElement();
			tw.WriteEndDocument();
			
			//clean up
			tw.Flush();
			tw.Close();
		}
	}
}
